package com.lxs.votesystem.util;
/**
 * 分页辅助类
 * @author Administrator
 *
 */
public class PageUtil {
	public static Page createPage(Integer everyPage, Integer currentPage, Integer totalCount) {
		if (everyPage == null || everyPage == 0) {
			everyPage = 10;
		}
		
		if (currentPage == null || currentPage == 0) {
			currentPage = 1;
		}
		
		Integer totalPage = (totalCount % everyPage) == 0 ? (totalCount / everyPage) : (totalCount / everyPage) + 1;
		
		if (currentPage > totalPage) {
			currentPage = totalPage;
		}
		
		Integer beginIndex = (currentPage - 1) * everyPage;
		
		boolean hasPrePage = currentPage == 1 ? false : true;
		
		boolean hasNextPage = currentPage == totalPage ? false : true;
		return new Page(everyPage, currentPage, totalPage, totalCount, beginIndex, hasPrePage, hasNextPage);
	}
}
